<?php
function sortByKeyValue($data, $sortKey, $sort_flags = SORT_ASC){
	if (empty($data) or empty($sortKey)) return $data;

	$ordered = array();
	foreach ($data as $key => $value)$ordered[$value[$sortKey]] = $value;
	ksort($ordered, $sort_flags);
	return ($ordered); 
}

function lastIndexOf($str, $value, $startIndex = null) {
    $target = strrpos($str, $value, $startIndex === null ? null : strlen($str) - $startIndex);
    if($target === false) return -1;
    else return $target;
}

function removeDir($path) {
	if(is_dir($path)){
		// Normalise $path.
		$path = rtrim($path, '/') . '/';
	
		// Remove all child files and directories.
		$items = glob($path . '*');
	
		foreach($items as $item) {
			is_dir($item) ? removeDir($item) : unlink($item);
		}
	
		// Remove directory.
		rmdir($path);
	}
}

function generateReceiptCode($userId){
    $now = date("dmYHis");
    return $now.$userId;    
}
?>